package com.jingsong.studentapp.adapter;
/*
 * @author zei , QQ:77132995, email:kazeik@163.com
 * 2021-12-17 23:02
 * 类说明:
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class BaseAdapter<A> extends RecyclerView.Adapter<KBaseViewHolder> {
    public abstract int getLaoutView();

    private LayoutInflater layoutInflater;
    private List<A> datas;

    public List<A> getDatas() {
        return datas;
    }

    public void setDatas(List<A> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clearAll() {
        if (null != datas && !datas.isEmpty()) {
            datas.clear();
            notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return datas != null && !datas.isEmpty() ? datas.size() : 0;
    }

    @NonNull
    @Override
    public KBaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        layoutInflater = LayoutInflater.from(parent.getContext());
        return new KBaseViewHolder(layoutInflater.inflate(getLaoutView(), parent, false), parent.getContext());
    }
}
